import Icon from '@/components/Icon';
import NavBar from '@/components/NavBar';
import { useRef, useState } from 'react';
// import classnames from 'classnames';
import styles from './index.module.scss';

export default function Search() {
  const tiemIdRef = useRef(-1);
  const [searchValue, setSearchValue] = useState('');
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setSearchValue(e.target.value);
    clearTimeout(tiemIdRef.current);
    tiemIdRef.current = window.setTimeout(() => {
      if (!searchValue.trim()) return;
      console.log('111111', 111111);
      setSearchValue(e.target.value);
    }, 500);
  };
  return (
    <div className={styles.root}>
      {/* 顶部导航栏 */}
      <NavBar right={<span className="search-text">搜索</span>}>
        <div className="navbar-search">
          <Icon type="iconbtn_search" className="icon-search" />

          <div className="input-wrapper">
            {/* 输入框 */}
            <input
              type="text"
              placeholder="请输入关键字搜索"
              value={searchValue}
              onChange={(e) => handleChange(e)}
            />

            {/* 清空输入框按钮 */}
            <Icon
              type="iconbtn_tag_close"
              className="icon-close"
              onClick={() => setSearchValue('')}
            />
          </div>
        </div>
      </NavBar>

      {/* 搜索历史 */}
      <div className="history" style={{ display: 'block' }}>
        <div className="history-header">
          <span>搜索历史</span>
          <span>
            <Icon type="iconbtn_del" />
            清除全部
          </span>
        </div>

        <div className="history-list">
          <span className="history-item">
            Python生成九宫格图片<span className="divider"></span>
          </span>
          <span className="history-item">
            Python<span className="divider"></span>
          </span>
          <span className="history-item">
            CSS<span className="divider"></span>
          </span>
          <span className="history-item">
            数据分析<span className="divider"></span>
          </span>
        </div>
      </div>

      {/* 搜素建议结果列表 */}
      <div className="search-result">
        <div className="result-item">
          <Icon className="icon-search" type="iconbtn_search" />
          <div className="result-value">
            <span>{'高亮'}</span>
            {`其余`}
          </div>
        </div>
      </div>
    </div>
  );
}
